<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8" />
		<title>1.localStorage</title>
	</head>
	<body>
		<button onclick="savePerson()">向localStorage中存入一个人</button> <br><br>
		<button onclick="getPerson()">从localStorage中读取一个人</button> <br><br>
		<button onclick="updatePerson()">修改localStorage中的一个人</button> <br><br>
		<button onclick="deletePerson()">删除localStorage中的一个人</button> <br><br>
		<button onclick="clearAllData()">清空localStorage</button>

		<script type="text/javascript" >
			//准备好一个人
			const person = {name:'张三',age:18}
			const person2 = {name:'李四',age:30}

			//写入
			function savePerson(){
				localStorage.setItem("ren",JSON.stringify(person))
			}
			//读取
			function getPerson(){
				/* 读取不到是null，JSON.parse(null)的结果依然是null */
				const result = localStorage.getItem("ren")
				console.log(JSON.parse(result))
			}
			//修改
			function updatePerson(){
				localStorage.setItem("ren",JSON.stringify(person2))
			}
			//删除
			function deletePerson(){
				localStorage.removeItem('ren')
			}
			//清空
			function clearAllData(){
				localStorage.clear()
			}

		</script>
	</body>
</html>